package com.goldstone.actions;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springside.modules.orm.Page;

import com.dbb.util.ResourceUtil;
import com.goldstone.entity.OrderPager;
import com.opensymphony.xwork2.ActionSupport;

@Namespace("")
@Results({ 
	@Result(name = "report", location = "/report/catalog.jasper", type = "jasper", params = {"dataSource", "dataSource"}),
	@Result(name = "welcome", location = "welcome", type = "tiles")
})
public class MainAction extends ActionSupport{
	
	private static final long serialVersionUID = -6456145401441423430L;
	Page page = new Page(10);
	String hello = "Welcome";
	OrderPager order = new OrderPager();
	String dataSource = "";
//	@Autowired
//	ContactService contactService;
	public String welcome() {
		return "welcome";
	}
	public String report() {
//		JasperReportsResult jr;
		try {
			JasperCompileManager.compileReportToFile(
					ResourceUtil.FROM + "/report/catalog.jrxml",
					ResourceUtil.TO + "/report/catalog.jasper");
		} catch (JRException e) {
			e.printStackTrace();
		}
		return "report";
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getHello() {
		return hello;
	}

	public String getDataSource() {
		return dataSource;
	}

	public OrderPager getOrder() {
		order.setBuyer("福建新吉福企业有限公司");
		order.setSupplier("扬州华钰工艺品有限公司");
		return order;
	}

	public void setOrder(OrderPager order) {
		this.order = order;
	}

}
